package sair.player.ui;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JList;
import javax.swing.JProgressBar;

import sair.player.PlayerActivity;
import sair.player.acts.PlayerActions;

class ListClick extends java.awt.event.MouseAdapter {
	private JList<String> jl;
	private PlayerActivity pa;

	public ListClick(JList<String> jl, PlayerActivity pa) {
		this.jl = jl;
		this.pa = pa;
	}

	@Override
	public void mouseClicked(MouseEvent e) {

		if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
			int index = jl.getSelectedIndex();
			if (index < pa.getList().listSize() && index >= 0)
				pa.getPA().start(index, false, true, true);
		} else if (e.getButton() == MouseEvent.BUTTON3 && e.getClickCount() == 2) {
			int index = jl.getSelectedIndex();
			if (index < pa.getList().listSize() && index >= 0)
				pa.getPA().remove(index);
		}
	}

}

class BarClick extends MouseAdapter {
	private JProgressBar jb;
	private PlayerActions paction;

	BarClick(JProgressBar jb, PlayerActions paction) {
		this.jb = jb;
		this.paction = paction;
	}

	public void mousePressed(MouseEvent e) {
		float max = jb.getWidth();
		float mx = e.getX();
		float mResult = mx / max;
		paction.setPlayPos(mResult);
	}
}